package cn.bby.tools.actions.str.convert;

import cn.bby.tools.actions.str.BaseStringProcessAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;

/**
 * @author ben
 * @since 2025/9/24 20:27
 */
public class RemoveExtraSpace extends BaseStringProcessAction {
    @Override
    public String process(@NotNull AnActionEvent e, String selectedText) {
        if (!selectedText.contains(" ")) {
            return selectedText;
        }
        String replace = selectedText;
        while (true) {
            int length = replace.length();
            replace = replace.replace("  ", " ");
            if (replace.length() == length) {
                return selectedText;
            }
            selectedText = replace;
        }
    }
}
